package eteam.aps.systemservice.config;

import eteam.aps.systemservice.common.StringToEnumConverterFactory;
import eteam.aps.systemservice.common.SystemInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(new StringToEnumConverterFactory());
        WebMvcConfigurer.super.addFormatters(registry);
    }

    @Bean
    public SystemInterceptor systemInterceptor() {
        return new SystemInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(systemInterceptor());
        registration.addPathPatterns("/**");
        registration.excludePathPatterns(
                "/api/getnow",
                "/api/getnow01",
                "/api/postinfo",

                "/api/auth/buildtoken",
                "/api/auth/verifytoken",
                "/api/user/findselfpwd",
                "/api/system/getmoduleopers",
                "/api/flow/**",

                "/error",
                "/favicon.ico",
                "/doc.html",
                "/swagger-ui.html",
                "/swagger-resources/**",
                "/webjars/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
